<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width"/>

<meta name="theme-color" content="#414852"/>


<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inconsolata|Itim|Lobster.css">
<link rel="icon" type="image/png" sizes="64x64" href="/images/favicon/xin-64.png" /><link rel="icon" type="image/png" sizes="128x128" href="/images/favicon/xin-128.png" /><link rel="apple-touch-icon" sizes="128x128" href="/images/favicon/xin-128.png" /><link rel="mask-icon" color="white" href="/images/favicon/xin.svg" />  <meta name="description" content="Spring5现处在第四个预发布版，正式版将要发布了，它带来的一大特性就是响应式框架Spring WebFlux。默认使用ProjectReactor框架。因此。本文通过ProjectReactor中的Flux，来学习使用该框架，以及了解其传递的思想。    本文基于Reactor3.1 rc1     Reactor官方地址http:&#x2F;&#x2F;projectreactor.io&#x2F;，官方文档写的十分详细">
<meta property="og:type" content="article">
<meta property="og:title" content="Java ProjectReactor框架之Flux篇">
<meta property="og:url" content="https://jiangtj.com/articles/almond/Java%20ProjectReactor-Flux/index.html">
<meta property="og:site_name" content="Dnocm ☀">
<meta property="og:description" content="Spring5现处在第四个预发布版，正式版将要发布了，它带来的一大特性就是响应式框架Spring WebFlux。默认使用ProjectReactor框架。因此。本文通过ProjectReactor中的Flux，来学习使用该框架，以及了解其传递的思想。    本文基于Reactor3.1 rc1     Reactor官方地址http:&#x2F;&#x2F;projectreactor.io&#x2F;，官方文档写的十分详细">
<meta property="og:locale">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/combinelatest.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/concat.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/defer.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/firstemitting.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/fromarray.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/generate.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/interval.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/justn.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/merge.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/never.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/switchonnext.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/using.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/zip.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/concatmap.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/concat.png">
<meta property="og:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/groupby.png">
<meta property="article:published_time" content="2017-09-16T16:00:00.000Z">
<meta property="article:modified_time" content="2017-09-16T16:00:00.000Z">
<meta property="article:author" content="Mr.J">
<meta property="article:tag" content="WebFlux">
<meta property="article:tag" content="Reactor">
<meta property="article:tag" content="Reactive">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/combinelatest.png">  <title>Java ProjectReactor框架之Flux篇 | Dnocm ☀</title>    <script type="application/ld+json">{"@context":"https://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://jiangtj.com/articles/almond/Java%20ProjectReactor-Flux/"},"headline":"Java ProjectReactor框架之Flux篇","image":[],"datePublished":"2017-09-16T16:00:00.000Z","dateModified":"2017-09-16T16:00:00.000Z","author":{"@type":"Person","name":"Mr.J"},"publisher":{"@type":"Organization","name":"Mr.J","logo":{"@type":"ImageObject","url":"https://jiangtj.com/images/avatar.jpg"}}}</script><script data-ad-client="ca-pub-8243423215749776" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<meta name="google-site-verification" content="TWf4Ma3V7xRcvKFWw_1iOCJKgNJmUUB1CmLucKjvV2A" />
<meta name="baidu-site-verification" content="xtf2YgRPUK" />

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-132230328-1"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-132230328-1');
</script>
<link rel="stylesheet" type="text/css" href="/css/injector/main.css" /><link rel="preload" as="style" href="/css/injector/light.css" /><link rel="preload" as="style" href="/css/injector/dark.css" /><link rel="preload" as="style" href="/css/injector/auto.css" /><!-- hexo injector head_end start --><link rel="manifest" href="/manifest.json" /><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.1.0"><link rel="alternate" href="/rss2.xml" title="Dnocm ☀" type="application/rss+xml">
</head>

<body>

    
  <header class="main-header">
    <div class="header-inner card"><div class="brand">
  <div class="site-meta">
    <div class="custom-logo-site-title">
      <a href="/">
        <span class="site-title">Dnocm ☀</span>
      </a>
    </div>
    
  </div>

  <div class="site-nav-toggle">
    <button>
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="bars" class="svg-inline--fa fa-bars icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path></svg>    </button>
  </div>
</div>
<nav class="site-nav">
  <ul class="menu">
    <li class="menu-item menu-item-home"><a href="/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="home" class="svg-inline--fa fa-home icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z"></path></svg>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="tags" class="svg-inline--fa fa-tags icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M497.941 225.941L286.059 14.059A48 48 0 0 0 252.118 0H48C21.49 0 0 21.49 0 48v204.118a48 48 0 0 0 14.059 33.941l211.882 211.882c18.744 18.745 49.136 18.746 67.882 0l204.118-204.118c18.745-18.745 18.745-49.137 0-67.882zM112 160c-26.51 0-48-21.49-48-48s21.49-48 48-48 48 21.49 48 48-21.49 48-48 48zm513.941 133.823L421.823 497.941c-18.745 18.745-49.137 18.745-67.882 0l-.36-.36L527.64 323.522c16.999-16.999 26.36-39.6 26.36-63.64s-9.362-46.641-26.36-63.64L331.397 0h48.721a48 48 0 0 1 33.941 14.059l211.882 211.882c18.745 18.745 18.745 49.137 0 67.882z"></path></svg>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="th" class="svg-inline--fa fa-th icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M149.333 56v80c0 13.255-10.745 24-24 24H24c-13.255 0-24-10.745-24-24V56c0-13.255 10.745-24 24-24h101.333c13.255 0 24 10.745 24 24zm181.334 240v-80c0-13.255-10.745-24-24-24H205.333c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h101.333c13.256 0 24.001-10.745 24.001-24zm32-240v80c0 13.255 10.745 24 24 24H488c13.255 0 24-10.745 24-24V56c0-13.255-10.745-24-24-24H386.667c-13.255 0-24 10.745-24 24zm-32 80V56c0-13.255-10.745-24-24-24H205.333c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h101.333c13.256 0 24.001-10.745 24.001-24zm-205.334 56H24c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h101.333c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24zM0 376v80c0 13.255 10.745 24 24 24h101.333c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H24c-13.255 0-24 10.745-24 24zm386.667-56H488c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H386.667c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24zm0 160H488c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H386.667c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24zM181.333 376v80c0 13.255 10.745 24 24 24h101.333c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H205.333c-13.255 0-24 10.745-24 24z"></path></svg>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="archive" class="svg-inline--fa fa-archive icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M32 448c0 17.7 14.3 32 32 32h384c17.7 0 32-14.3 32-32V160H32v288zm160-212c0-6.6 5.4-12 12-12h104c6.6 0 12 5.4 12 12v8c0 6.6-5.4 12-12 12H204c-6.6 0-12-5.4-12-12v-8zM480 32H32C14.3 32 0 46.3 0 64v48c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16V64c0-17.7-14.3-32-32-32z"></path></svg>归档</a></li><li class="menu-item menu-item-more"><a href="/more/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>More</a></li><li class="menu-item menu-item-search"><a href="javascript:;" class="popup-trigger"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="search" class="svg-inline--fa fa-search icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"></path></svg>搜索</a></li>  </ul>
</nav>
</div>
  </header>

  <div class="flex-container">

    

<aside class="sidebar">

  <div class="header-inner card">
    <div class="brand">
  <div class="site-meta">
    <div class="custom-logo-site-title">
      <a href="/">
        <span class="site-title">Dnocm ☀</span>
      </a>
    </div>
    
  </div>

  <div class="site-nav-toggle">
    <button>
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="bars" class="svg-inline--fa fa-bars icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path></svg>    </button>
  </div>
</div>
<nav class="site-nav">
  <ul class="menu">
    <li class="menu-item menu-item-home"><a href="/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="home" class="svg-inline--fa fa-home icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z"></path></svg>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="tags" class="svg-inline--fa fa-tags icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M497.941 225.941L286.059 14.059A48 48 0 0 0 252.118 0H48C21.49 0 0 21.49 0 48v204.118a48 48 0 0 0 14.059 33.941l211.882 211.882c18.744 18.745 49.136 18.746 67.882 0l204.118-204.118c18.745-18.745 18.745-49.137 0-67.882zM112 160c-26.51 0-48-21.49-48-48s21.49-48 48-48 48 21.49 48 48-21.49 48-48 48zm513.941 133.823L421.823 497.941c-18.745 18.745-49.137 18.745-67.882 0l-.36-.36L527.64 323.522c16.999-16.999 26.36-39.6 26.36-63.64s-9.362-46.641-26.36-63.64L331.397 0h48.721a48 48 0 0 1 33.941 14.059l211.882 211.882c18.745 18.745 18.745 49.137 0 67.882z"></path></svg>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="th" class="svg-inline--fa fa-th icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M149.333 56v80c0 13.255-10.745 24-24 24H24c-13.255 0-24-10.745-24-24V56c0-13.255 10.745-24 24-24h101.333c13.255 0 24 10.745 24 24zm181.334 240v-80c0-13.255-10.745-24-24-24H205.333c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h101.333c13.256 0 24.001-10.745 24.001-24zm32-240v80c0 13.255 10.745 24 24 24H488c13.255 0 24-10.745 24-24V56c0-13.255-10.745-24-24-24H386.667c-13.255 0-24 10.745-24 24zm-32 80V56c0-13.255-10.745-24-24-24H205.333c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h101.333c13.256 0 24.001-10.745 24.001-24zm-205.334 56H24c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h101.333c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24zM0 376v80c0 13.255 10.745 24 24 24h101.333c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H24c-13.255 0-24 10.745-24 24zm386.667-56H488c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H386.667c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24zm0 160H488c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H386.667c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24zM181.333 376v80c0 13.255 10.745 24 24 24h101.333c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24H205.333c-13.255 0-24 10.745-24 24z"></path></svg>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="archive" class="svg-inline--fa fa-archive icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M32 448c0 17.7 14.3 32 32 32h384c17.7 0 32-14.3 32-32V160H32v288zm160-212c0-6.6 5.4-12 12-12h104c6.6 0 12 5.4 12 12v8c0 6.6-5.4 12-12 12H204c-6.6 0-12-5.4-12-12v-8zM480 32H32C14.3 32 0 46.3 0 64v48c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16V64c0-17.7-14.3-32-32-32z"></path></svg>归档</a></li><li class="menu-item menu-item-more"><a href="/more/"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path></svg>More</a></li><li class="menu-item menu-item-search"><a href="javascript:;" class="popup-trigger"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="search" class="svg-inline--fa fa-search icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"></path></svg>搜索</a></li>  </ul>
</nav>
  </div>

  <div class="sidebar-inner card">

    

    <ul class="sidebar-nav">
      <li class="sidebar-nav-toc sidebar-nav-active">
        文章目录
      </li>
      <li class="sidebar-nav-overview">
        站点概览
      </li>
    </ul>
    <div class="post-toc-wrap sidebar-panel sidebar-panel-active">
      <div class="post-toc"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#Spring-WebFlux-%E5%AE%9E%E8%B7%B5"><span class="nav-number">1.</span> <span class="nav-text">Spring WebFlux 实践</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#step1-%E6%90%AD%E5%BB%BA%E7%8E%AF%E5%A2%83"><span class="nav-number">1.1.</span> <span class="nav-text">step1:搭建环境</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#step2-%E7%BC%96%E5%86%99%E5%A4%84%E7%90%86%E7%B1%BB"><span class="nav-number">1.2.</span> <span class="nav-text">step2:编写处理类</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#step3-%E7%BC%96%E5%86%99%E8%B7%AF%E7%94%B1"><span class="nav-number">1.3.</span> <span class="nav-text">step3:编写路由</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#step4-%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%AA%8C%E8%AF%81"><span class="nav-number">1.4.</span> <span class="nav-text">step4:测试，验证</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%B7%B1%E5%85%A5%E5%AD%A6%E4%B9%A0"><span class="nav-number">2.</span> <span class="nav-text">深入学习</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9D%99%E6%80%81%E6%96%B9%E6%B3%95"><span class="nav-number">3.</span> <span class="nav-text">静态方法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#combineLatest"><span class="nav-number">3.1.</span> <span class="nav-text">combineLatest</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#concat"><span class="nav-number">3.2.</span> <span class="nav-text">concat</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#concatDelayError"><span class="nav-number">3.3.</span> <span class="nav-text">concatDelayError</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#create-push"><span class="nav-number">3.4.</span> <span class="nav-text">create,push</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#backpressure-%E8%83%8C%E5%8E%8B-%E6%A6%82%E5%BF%B5%E7%9A%84%E7%90%86%E8%A7%A3"><span class="nav-number">3.4.1.</span> <span class="nav-text">backpressure(背压)概念的理解</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#defer"><span class="nav-number">3.5.</span> <span class="nav-text">defer</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#empty"><span class="nav-number">3.6.</span> <span class="nav-text">empty</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#error"><span class="nav-number">3.7.</span> <span class="nav-text">error</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#first"><span class="nav-number">3.8.</span> <span class="nav-text">first</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#from"><span class="nav-number">3.9.</span> <span class="nav-text">from</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#fromArray%EF%BC%8CfromIterable%EF%BC%8CfromStream"><span class="nav-number">3.10.</span> <span class="nav-text">fromArray，fromIterable，fromStream</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#generate"><span class="nav-number">3.11.</span> <span class="nav-text">generate</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#interval"><span class="nav-number">3.12.</span> <span class="nav-text">interval</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#just"><span class="nav-number">3.13.</span> <span class="nav-text">just</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#merge"><span class="nav-number">3.14.</span> <span class="nav-text">merge</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#never"><span class="nav-number">3.15.</span> <span class="nav-text">never</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#range"><span class="nav-number">3.16.</span> <span class="nav-text">range</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#switchOnNext"><span class="nav-number">3.17.</span> <span class="nav-text">switchOnNext</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#using"><span class="nav-number">3.18.</span> <span class="nav-text">using</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#zip"><span class="nav-number">3.19.</span> <span class="nav-text">zip</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E2%80%A6"><span class="nav-number">3.20.</span> <span class="nav-text">…</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E5%AE%9E%E4%BE%8B%E6%96%B9%E6%B3%95"><span class="nav-number">4.</span> <span class="nav-text">常用的实例方法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#all-any-hasElement-hasElements"><span class="nav-number">4.1.</span> <span class="nav-text">all,any,hasElement,hasElements</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#as-compose"><span class="nav-number">4.2.</span> <span class="nav-text">as,compose</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#blockFirst-blockLast"><span class="nav-number">4.3.</span> <span class="nav-text">blockFirst,blockLast</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#butter%E7%B3%BB%E5%88%97"><span class="nav-number">4.4.</span> <span class="nav-text">butter系列</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#cache"><span class="nav-number">4.5.</span> <span class="nav-text">cache</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#cancelOn"><span class="nav-number">4.6.</span> <span class="nav-text">cancelOn</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#cast"><span class="nav-number">4.7.</span> <span class="nav-text">cast</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#checkpoint"><span class="nav-number">4.8.</span> <span class="nav-text">checkpoint</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#collect%E7%B3%BB%E5%88%97"><span class="nav-number">4.9.</span> <span class="nav-text">collect系列</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#concatMap%E7%B3%BB%E5%88%97-flatMap%E7%B3%BB%E5%88%97"><span class="nav-number">4.10.</span> <span class="nav-text">concatMap系列,flatMap系列</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#concatWith"><span class="nav-number">4.11.</span> <span class="nav-text">concatWith</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#defaultIfEmpty"><span class="nav-number">4.12.</span> <span class="nav-text">defaultIfEmpty</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#distinct"><span class="nav-number">4.13.</span> <span class="nav-text">distinct</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#do%E7%B3%BB%E5%88%97"><span class="nav-number">4.14.</span> <span class="nav-text">do系列</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#elementAt"><span class="nav-number">4.15.</span> <span class="nav-text">elementAt</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#filter"><span class="nav-number">4.16.</span> <span class="nav-text">filter</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#groupBy"><span class="nav-number">4.17.</span> <span class="nav-text">groupBy</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#mark"><span class="nav-number">4.18.</span> <span class="nav-text">mark</span></a></li></ol></li></ol></div>
    </div>
    <div class="site-overview-wrap sidebar-panel">
      <div class="site-overview">
  <div class="site-author">
    
    <img class="site-author-image" src="/images/avatar.jpg"
      alt="Mr.J" />
    
    <p class="site-author-name">Mr.J</p>
    <div class="site-description">何须更问浮生事，只此浮生是梦中</div>
  </div>

  <nav class="site-state">
    
    <div class="site-state-item site-state-posts">
      <a href="/archives/">
        <span class="site-state-item-count">64</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    

    
    <div class="site-state-item site-state-categories">
      <a href="/categories/">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span>
      </a>
    </div>
    

    
    <div class="site-state-item site-state-tags">
      <a href="/tags/">
        <span class="site-state-item-count">48</span>
        <span class="site-state-item-name">标签</span>
      </a>
    </div>
    
  </nav>

  <div class="social-links"><a href="mailto:i@dnocm.com" title="mailto:i@dnocm.com" rel="noopener" target="_blank"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="envelope" class="svg-inline--fa fa-envelope icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M502.3 190.8c3.9-3.1 9.7-.2 9.7 4.7V400c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V195.6c0-5 5.7-7.8 9.7-4.7 22.4 17.4 52.1 39.5 154.1 113.6 21.1 15.4 56.7 47.8 92.2 47.6 35.7.3 72-32.8 92.3-47.6 102-74.1 131.6-96.3 154-113.7zM256 320c23.2.4 56.6-29.2 73.4-41.4 132.7-96.3 142.8-104.7 173.4-128.7 5.8-4.5 9.2-11.5 9.2-18.9v-19c0-26.5-21.5-48-48-48H48C21.5 64 0 85.5 0 112v19c0 7.4 3.4 14.3 9.2 18.9 30.6 23.9 40.7 32.4 173.4 128.7 16.8 12.2 50.2 41.8 73.4 41.4z"></path></svg></a><a href="https://t.me/dnocm" title="https://t.me/dnocm" rel="noopener" target="_blank"><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="telegram" class="svg-inline--fa fa-telegram icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path fill="currentColor" d="M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm121.8 169.9l-40.7 191.8c-3 13.6-11.1 16.9-22.4 10.5l-62-45.7-29.9 28.8c-3.3 3.3-6.1 6.1-12.5 6.1l4.4-63.1 114.9-103.8c5-4.4-1.1-6.9-7.7-2.5l-142 89.4-61.2-19.1c-13.3-4.2-13.6-13.3 2.8-19.7l239.1-92.2c11.1-4 20.8 2.7 17.2 19.5z"></path></svg></a><a href="/rss2.xml" title="/rss2.xml" rel="noopener" target="_blank"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="rss" class="svg-inline--fa fa-rss icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M128.081 415.959c0 35.369-28.672 64.041-64.041 64.041S0 451.328 0 415.959s28.672-64.041 64.041-64.041 64.04 28.673 64.04 64.041zm175.66 47.25c-8.354-154.6-132.185-278.587-286.95-286.95C7.656 175.765 0 183.105 0 192.253v48.069c0 8.415 6.49 15.472 14.887 16.018 111.832 7.284 201.473 96.702 208.772 208.772.547 8.397 7.604 14.887 16.018 14.887h48.069c9.149.001 16.489-7.655 15.995-16.79zm144.249.288C439.596 229.677 251.465 40.445 16.503 32.01 7.473 31.686 0 38.981 0 48.016v48.068c0 8.625 6.835 15.645 15.453 15.999 191.179 7.839 344.627 161.316 352.465 352.465.353 8.618 7.373 15.453 15.999 15.453h48.068c9.034-.001 16.329-7.474 16.005-16.504z"></path></svg></a><a href="https://github.com/JiangTJ" title="https://github.com/JiangTJ" rel="noopener" target="_blank"><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="github" class="svg-inline--fa fa-github icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path fill="currentColor" d="M165.9 397.4c0 2-2.3 3.6-5.2 3.6-3.3.3-5.6-1.3-5.6-3.6 0-2 2.3-3.6 5.2-3.6 3-.3 5.6 1.3 5.6 3.6zm-31.1-4.5c-.7 2 1.3 4.3 4.3 4.9 2.6 1 5.6 0 6.2-2s-1.3-4.3-4.3-5.2c-2.6-.7-5.5.3-6.2 2.3zm44.2-1.7c-2.9.7-4.9 2.6-4.6 4.9.3 2 2.9 3.3 5.9 2.6 2.9-.7 4.9-2.6 4.6-4.6-.3-1.9-3-3.2-5.9-2.9zM244.8 8C106.1 8 0 113.3 0 252c0 110.9 69.8 205.8 169.5 239.2 12.8 2.3 17.3-5.6 17.3-12.1 0-6.2-.3-40.4-.3-61.4 0 0-70 15-84.7-29.8 0 0-11.4-29.1-27.8-36.6 0 0-22.9-15.7 1.6-15.4 0 0 24.9 2 38.6 25.8 21.9 38.6 58.6 27.5 72.9 20.9 2.3-16 8.8-27.1 16-33.7-55.9-6.2-112.3-14.3-112.3-110.5 0-27.5 7.6-41.3 23.6-58.9-2.6-6.5-11.1-33.3 2.6-67.9 20.9-6.5 69 27 69 27 20-5.6 41.5-8.5 62.8-8.5s42.8 2.9 62.8 8.5c0 0 48.1-33.6 69-27 13.7 34.7 5.2 61.4 2.6 67.9 16 17.7 25.8 31.5 25.8 58.9 0 96.5-58.9 104.2-114.8 110.5 9.2 7.9 17 22.9 17 46.4 0 33.7-.3 75.4-.3 83.6 0 6.5 4.6 14.4 17.3 12.1C428.2 457.8 496 362.9 496 252 496 113.3 383.5 8 244.8 8zM97.2 352.9c-1.3 1-1 3.3.7 5.2 1.6 1.6 3.9 2.3 5.2 1 1.3-1 1-3.3-.7-5.2-1.6-1.6-3.9-2.3-5.2-1zm-10.8-8.1c-.7 1.3.3 2.9 2.3 3.9 1.6 1 3.6.7 4.3-.7.7-1.3-.3-2.9-2.3-3.9-2-.6-3.6-.3-4.3.7zm32.4 35.6c-1.6 1.3-1 4.3 1.3 6.2 2.3 2.3 5.2 2.6 6.5 1 1.3-1.3.7-4.3-1.3-6.2-2.2-2.3-5.2-2.6-6.5-1zm-11.4-14.7c-1.6 1-1.6 3.6 0 5.9 1.6 2.3 4.3 3.3 5.6 2.3 1.6-1.3 1.6-3.9 0-6.2-1.4-2.3-4-3.3-5.6-2z"></path></svg></a></div><div class="font-size-ol"><a class="font-size-ol-sub">A-</a><span class="font-size-ol-value">14</span><a class="font-size-ol-plus">A+</a></div>
</div>
    </div>

    

  </div>
</aside>

    <div class="flex-main">

      <main>
        
        <div id="content" class="content">
          <div>
  

<article class="post post-type-normal">
  <div class="card post-block">

    

    <header class="post-header">

      
      <h1 class="post-title">
        
        Java ProjectReactor框架之Flux篇
        
      </h1>
      

      <div class="post-meta">

  
  
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="calendar" class="svg-inline--fa fa-calendar icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M400 64h-48V12c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v52H160V12c0-6.6-5.4-12-12-12h-40c-6.6 0-12 5.4-12 12v52H48C21.5 64 0 85.5 0 112v352c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V112c0-26.5-21.5-48-48-48zm-6 400H54c-3.3 0-6-2.7-6-6V160h352v298c0 3.3-2.7 6-6 6z"></path></svg>
    </span>
    <span class="post-meta-item-text">发表于</span>
    <time title="创建时间：2017-09-17 00:00:00">2017-09-17</time>
  </span>
  

  

  
  
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="folder" class="svg-inline--fa fa-folder icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M464 128H272l-64-64H48C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V176c0-26.51-21.49-48-48-48z"></path></svg>
    </span>
    <span class="post-meta-item-text">分类于</span>
    <span><a href="/categories/%E5%90%8E%E7%AB%AF/" rel="index"><span>后端</span></a></span>  </span>
  

  
  

</div>

    </header>

    <div class="post-body">
      
      <p>Spring5现处在第四个预发布版，正式版将要发布了，它带来的一大特性就是响应式框架Spring WebFlux。默认使用ProjectReactor框架。因此。本文通过ProjectReactor中的Flux，来学习使用该框架，以及了解其传递的思想。   </p>
<p>本文基于Reactor3.1 rc1    </p>
<p>Reactor官方地址<a target="_blank" rel="noopener" href="http://projectreactor.io/">http://projectreactor.io/</a>，官方文档写的十分详细，如果您有不错的英文能力，建议直接阅读官方文档。  </p>
<span id="more"></span>

<h3 id="Spring-WebFlux-实践" class="article-heading"><a href="#Spring-WebFlux-实践" class="headerlink" title="Spring WebFlux 实践"></a>Spring WebFlux 实践<a class="article-anchor" href="#Spring-WebFlux-实践" aria-hidden="true"></a></h3><p>首先，为大家带来一个使用了ProjectReactor的例子，该例子使用Spring Boot 2.0.0.BUILD-SNAPSHOT。因Spring Boot推荐默认配置（约定）优先，可以极大减少大量的重复的模版化代码，简化搭建过程。   </p>
<p><em>Spring Boot 2.0.0稳定版还未出，不过也快了，目前处在第四个里程碑版本。</em>   </p>
<h4 id="step1-搭建环境" class="article-heading"><a href="#step1-搭建环境" class="headerlink" title="step1:搭建环境"></a>step1:搭建环境<a class="article-anchor" href="#step1-搭建环境" aria-hidden="true"></a></h4><p>spring boot部分工具如idea提供了可视化操作，选择reactive-web模块即可（你也可以多选一些你需要的模块），如果没有可视化的工具，也可访问官网的开始页面<a target="_blank" rel="noopener" href="https://start.spring.io/">https://start.spring.io/</a>，或者在pom中引入一下模块（web开发主流仍是maven，所以未采用gradle）   </p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs xml"><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>org.springframework.boot<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>spring-boot-starter-webflux<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">dependency</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">groupId</span>&gt;</span>io.projectreactor<span class="hljs-tag">&lt;/<span class="hljs-name">groupId</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">artifactId</span>&gt;</span>reactor-test<span class="hljs-tag">&lt;/<span class="hljs-name">artifactId</span>&gt;</span><br>	<span class="hljs-tag">&lt;<span class="hljs-name">scope</span>&gt;</span>test<span class="hljs-tag">&lt;/<span class="hljs-name">scope</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">dependency</span>&gt;</span><br></code></pre></td></tr></table></figure>

<h4 id="step2-编写处理类" class="article-heading"><a href="#step2-编写处理类" class="headerlink" title="step2:编写处理类"></a>step2:编写处理类<a class="article-anchor" href="#step2-编写处理类" aria-hidden="true"></a></h4><p>编写一个简单的处理类，TestHandler    </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Service</span><br><span class="hljs-meta">@NonNullApi</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">TestHandler</span> &#123;<br><br>    <span class="hljs-keyword">public</span> Mono&lt;ServerResponse&gt; <span class="hljs-title function_">data</span><span class="hljs-params">(ServerRequest request)</span>&#123;<br>        Mono&lt;String&gt; mono =  Mono.justOrEmpty(request.queryParam(<span class="hljs-string">&quot;data&quot;</span>))<br>                .defaultIfEmpty(<span class="hljs-string">&quot;this is null&quot;</span>)<br>                .map(it -&gt; it.concat(<span class="hljs-string">&quot;! from server webflux!&quot;</span>));<br>        <span class="hljs-keyword">return</span> ServerResponse.ok().body(mono,String.class);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="step3-编写路由" class="article-heading"><a href="#step3-编写路由" class="headerlink" title="step3:编写路由"></a>step3:编写路由<a class="article-anchor" href="#step3-编写路由" aria-hidden="true"></a></h4><p>spring webflux也提供了函数试的路由配置，如下    </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@Configuration</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">RoutingConfiguration</span> &#123;<br><br>    <span class="hljs-comment">//...</span><br><br>    <span class="hljs-meta">@Bean</span><br>    <span class="hljs-keyword">public</span> RouterFunction&lt;ServerResponse&gt; <span class="hljs-title function_">testRouterFunction</span><span class="hljs-params">(TestHandler handle)</span> &#123;<br>        <span class="hljs-keyword">return</span> RouterFunctions.route(GET(<span class="hljs-string">&quot;/test&quot;</span>).and(accept(APPLICATION_JSON)), handle::data);<br>    &#125;<br><br>&#125;<br></code></pre></td></tr></table></figure>

<h4 id="step4-测试，验证" class="article-heading"><a href="#step4-测试，验证" class="headerlink" title="step4:测试，验证"></a>step4:测试，验证<a class="article-anchor" href="#step4-测试，验证" aria-hidden="true"></a></h4><p>当浏览器输入<a target="_blank" rel="noopener" href="http://localhost:8080/test%EF%BC%8C%E5%BE%97%E5%88%B0%E7%BB%93%E6%9E%9C%EF%BC%9Athis">http://localhost:8080/test，得到结果：this</a> is null! from server webflux!
当浏览器输入<a target="_blank" rel="noopener" href="http://localhost:8688/test?data=hi%EF%BC%8C%E5%BE%97%E5%88%B0%E7%BB%93%E6%9E%9C%EF%BC%9Ahi">http://localhost:8688/test?data=hi，得到结果：hi</a>! from server webflux!</p>
<p><em>我的webflux项目地址：<a target="_blank" rel="noopener" href="https://github.com/JiangTJ/circuasset">GitHub</a></em></p>
<h3 id="深入学习" class="article-heading"><a href="#深入学习" class="headerlink" title="深入学习"></a>深入学习<a class="article-anchor" href="#深入学习" aria-hidden="true"></a></h3><blockquote>
<p>看过实践后，你会发现有大量的使用Flux和Mono，它们是什么呢？</p>
</blockquote>
<p>Flux<T> 继承自 Publisher<T> ，用于代表拥有 0 到 n 元素的流，相对于 Mono<T> (其包含0-1个元素) 更加复杂。所以弄懂了Flux，其实也已经对Mono熟悉了。  </p>
<h3 id="静态方法" class="article-heading"><a href="#静态方法" class="headerlink" title="静态方法"></a>静态方法<a class="article-anchor" href="#静态方法" aria-hidden="true"></a></h3><p>Flux一般通过静态方法构造，所以先看看它的静态方法。 </p>
<h4 id="combineLatest" class="article-heading"><a href="#combineLatest" class="headerlink" title="combineLatest"></a>combineLatest<a class="article-anchor" href="#combineLatest" aria-hidden="true"></a></h4><p>public static &lt;T,V&gt; Flux<V> combineLatest(Function&lt;Object[],V&gt; combinator, Publisher&lt;? extends T&gt;… sources)<br>构建一个Flux，混合由多个的发布者发布最新事件.</p>
<p><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/combinelatest.png">  </p>
<p>Type Parameters:<br>T - 表示发布者的事件类型<br>V - 被混合者混合后的类型<br>Parameters:<br>sources - 发布者，提供事件<br>combinator - 混合者，接受最新的事件，处理并传递给下游。<br>Returns:  一个以Flux为基础的混合流<br><em>不同的参数方法很多，这里都只展示一个。</em>  </p>
<h4 id="concat" class="article-heading"><a href="#concat" class="headerlink" title="concat"></a>concat<a class="article-anchor" href="#concat" aria-hidden="true"></a></h4><p>public static <T> Flux<T> concat(Publisher&lt;? extends T&gt;… sources)<br>用于连接一个流。与combineLatest不同的是，concat都是在前一个流完成后在连接新的流。而combineLatest，则哪个事件最先到的，哪个先处理。  </p>
<p><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/concat.png">  </p>
<p>Type Parameters:<br>T - 事件的类型<br>Parameters:<br>sources - 一系列的发布者<br>Returns:  一个新的Flux连接了所有的发布者，并传递给下游    </p>
<h4 id="concatDelayError" class="article-heading"><a href="#concatDelayError" class="headerlink" title="concatDelayError"></a>concatDelayError<a class="article-anchor" href="#concatDelayError" aria-hidden="true"></a></h4><p>拥有与concat类似的方法，不同的是，遇到错误不提前拦截，而是等到最后发布的事件处理完成后</p>
<h4 id="create-push" class="article-heading"><a href="#create-push" class="headerlink" title="create,push"></a>create,push<a class="article-anchor" href="#create-push" aria-hidden="true"></a></h4><p>public static <T> Flux<T> create(Consumer&lt;? super FluxSink<T>&gt; emitter)<br>通过FluxSink API，以同步或者异步方式创建Flux。<br>例如：  </p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><code class="hljs java">Flux.&lt;String&gt;create(emitter -&gt; &#123;<br><br>    <span class="hljs-type">ActionListener</span> <span class="hljs-variable">al</span> <span class="hljs-operator">=</span> e -&gt; &#123;<br>        emitter.next(textField.getText());<br>    &#125;;<br>    <span class="hljs-comment">// without cleanup support:</span><br><br>    button.addActionListener(al);<br><br>    <span class="hljs-comment">// with cleanup support:</span><br><br>    button.addActionListener(al);<br>    emitter.onDispose(() -&gt; &#123;<br>        button.removeListener(al);<br>    &#125;);<br>&#125;);<br></code></pre></td></tr></table></figure>
<p>这是非常有用的，如果一个流，需要动态添加或者移除其他的多个事件，通过异步的api。而且，你将不必担心被取消和背压。<br><em>create(Consumer&lt;? super FluxSink<T>&gt; emitter, FluxSink.OverflowStrategy backpressure) 设置背压方式</em><br>push方法用处与使用方式与create几乎一致，它们唯一的区别在于CreateMode类型 create为PUSH_PULL，而push为PUSH_ONLY，从文档中也可以一个为多线程一个为单线程  </p>
<h5 id="backpressure-背压-概念的理解" class="article-heading"><a href="#backpressure-背压-概念的理解" class="headerlink" title="backpressure(背压)概念的理解"></a>backpressure(背压)概念的理解<a class="article-anchor" href="#backpressure-背压-概念的理解" aria-hidden="true"></a></h5><p>这里，我摘自一位大神的话，背压是指在异步场景中，被观察者发送事件速度远快于观察者的处理速度的情况下，一种告诉上游的被观察者降低发送速度的策略。简而言之，背压是流速控制的一种策略。  </p>
<blockquote>
<p>更多的背压到<a target="_blank" rel="noopener" href="http://www.jianshu.com/p/2c4799fa91a4">http://www.jianshu.com/p/2c4799fa91a4</a>这里不多做介绍了    </p>
</blockquote>
<h4 id="defer" class="article-heading"><a href="#defer" class="headerlink" title="defer"></a>defer<a class="article-anchor" href="#defer" aria-hidden="true"></a></h4><p>public static <T> Flux<T> defer(Supplier&lt;? extends Publisher<T>&gt; supplier)<br>这个方法提供了一种惰性策略，发布者不会一开始发布消息，直到订阅者创建实例.<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/defer.png"><br>Type Parameters:<br>T - 发布者发布或订阅者接受的类型<br>Parameters:<br>supplier - 一个发布者的供应者，当订阅的时候回调<br>Returns: 一个惰性的Flux  </p>
<h4 id="empty" class="article-heading"><a href="#empty" class="headerlink" title="empty"></a>empty<a class="article-anchor" href="#empty" aria-hidden="true"></a></h4><p>public static <T> Flux<T> empty()<br>创建一个不含任何事件的流.</p>
<h4 id="error" class="article-heading"><a href="#error" class="headerlink" title="error"></a>error<a class="article-anchor" href="#error" aria-hidden="true"></a></h4><p>public static <T> Flux<T> error(Throwable error)<br>返回一个带着立即终止标识和错误信息的流 </p>
<h4 id="first" class="article-heading"><a href="#first" class="headerlink" title="first"></a>first<a class="article-anchor" href="#first" aria-hidden="true"></a></h4><p>public static <I> Flux<I> first(Publisher&lt;? extends I&gt;… sources)<br>挑选出第一个发布者，由其提供事件。能有效避免多个源的冲突。<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/firstemitting.png">  </p>
<h4 id="from" class="article-heading"><a href="#from" class="headerlink" title="from"></a>from<a class="article-anchor" href="#from" aria-hidden="true"></a></h4><p>public static <T> Flux<T> from(Publisher&lt;? extends T&gt; source)<br>public static <T> Flux<T> fromIterable(Iterable&lt;? extends T&gt; it)<br>public static <T> Flux<T> fromStream(Stream&lt;? extends T&gt; s)<br>从一个发布者创建一个flux流  </p>
<h4 id="fromArray，fromIterable，fromStream" class="article-heading"><a href="#fromArray，fromIterable，fromStream" class="headerlink" title="fromArray，fromIterable，fromStream"></a>fromArray，fromIterable，fromStream<a class="article-anchor" href="#fromArray，fromIterable，fromStream" aria-hidden="true"></a></h4><p>public static <T> Flux<T> fromArray(T[] array)
通过一个数组，或者一个可迭代的元素，或者一个流，创建flux流.  </p>
<p><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/fromarray.png">  </p>
<p>Type Parameters:<br>T - 数组的类型和Flux的类型<br>Parameters:<br>emmm.. - 数组,可迭代的元素,流<br>Returns: 新的flux流  </p>
<h4 id="generate" class="article-heading"><a href="#generate" class="headerlink" title="generate"></a>generate<a class="article-anchor" href="#generate" aria-hidden="true"></a></h4><p>public static <T> Flux<T> generate(Consumer&lt;SynchronousSink<T>&gt; generator)<br>Programmatically create a Flux by generating signals one-by-one via a consumer callback.  </p>
<p><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/generate.png">  </p>
<p>Type Parameters:<br>T - the value type emitted<br>Parameters:<br>generator - Consume the SynchronousSink provided per-subscriber by Reactor to generate a single signal on each pass.
Returns: a Flux<br>没看懂，好像是说，通过编程方式创建一个一对一的消费回调  </p>
<h4 id="interval" class="article-heading"><a href="#interval" class="headerlink" title="interval"></a>interval<a class="article-anchor" href="#interval" aria-hidden="true"></a></h4><p>public static Flux<Long> interval(Duration period)<br>间隔一定的时间，发送事件。<br>Runs on the Schedulers.parallel() Scheduler.<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/interval.png">  </p>
<h4 id="just" class="article-heading"><a href="#just" class="headerlink" title="just"></a>just<a class="article-anchor" href="#just" aria-hidden="true"></a></h4><p>public static <T> Flux<T> just(T… data)<br>创建一个包含一系列元素的flux流<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/justn.png">  </p>
<h4 id="merge" class="article-heading"><a href="#merge" class="headerlink" title="merge"></a>merge<a class="article-anchor" href="#merge" aria-hidden="true"></a></h4><p>public static <I> Flux<I> merge(Publisher&lt;? extends I&gt;… sources)<br>混合多个流，和combineLatest类似，但它要求是同类型的流合并，combineLatest需要提供合并方式<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/merge.png"> </p>
<h4 id="never" class="article-heading"><a href="#never" class="headerlink" title="never"></a>never<a class="article-anchor" href="#never" aria-hidden="true"></a></h4><p>public static <T> Flux<T> never()<br>Create a Flux that will never signal any data, error or completion signal.  </p>
<p><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/never.png">  </p>
<p>Type Parameters:<br>T - the Subscriber type target<br>Returns:<br>a never completing Flux<br>看一看，不是很明白，该流的用处。 </p>
<h4 id="range" class="article-heading"><a href="#range" class="headerlink" title="range"></a>range<a class="article-anchor" href="#range" aria-hidden="true"></a></h4><p>public static Flux<Integer> range(int start, int count)<br>提供从start，到start + count的所有整数的flux流</p>
<h4 id="switchOnNext" class="article-heading"><a href="#switchOnNext" class="headerlink" title="switchOnNext"></a>switchOnNext<a class="article-anchor" href="#switchOnNext" aria-hidden="true"></a></h4><p>public static <T> Flux<T> switchOnNext(Publisher&lt;? extends Publisher&lt;? extends T&gt;&gt; mergedPublishers)<br>从最新的发布者那里获取事件，如果有新的发布者加入，则改用新的发布者。<br>当最后一个发布者完成所有发布事件，并且没有发布者加入，则flux完成。<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/switchonnext.png"></p>
<h4 id="using" class="article-heading"><a href="#using" class="headerlink" title="using"></a>using<a class="article-anchor" href="#using" aria-hidden="true"></a></h4><p>public static &lt;T,D&gt; Flux<T> using(Callable&lt;? extends D&gt; resourceSupplier, Function&lt;? super D,? extends Publisher&lt;? extends T&gt;&gt; sourceSupplier, Consumer&lt;? super D&gt; resourceCleanup)<br>Uses a resource, generated by a supplier for each individual Subscriber, while streaming the values from a Publisher derived from the same resource and makes sure the resource is released if the sequence terminates or the Subscriber cancels.<br>Eager resource cleanup happens just before the source termination and exceptions raised by the cleanup Consumer may override the terminal even.</p>
<p><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/using.png"></p>
<h4 id="zip" class="article-heading"><a href="#zip" class="headerlink" title="zip"></a>zip<a class="article-anchor" href="#zip" aria-hidden="true"></a></h4><p>public static &lt;I,O&gt; Flux<O> zip(Function&lt;? super Object[],? extends O&gt; combinator, Publisher&lt;? extends I&gt;… sources)
通过混合者，合并多个流成一个输出流，一一对应合并
<img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/zip.png">  </p>
<h4 id="…" class="article-heading"><a href="#…" class="headerlink" title="…"></a>…<a class="article-anchor" href="#…" aria-hidden="true"></a></h4><p>看一下下面的api<br>public static &lt;T1,T2,T3,V&gt; Flux<V> combineLatest(Publisher&lt;? extends T1&gt; source1, Publisher&lt;? extends T2&gt; source2, Publisher&lt;? extends T3&gt; source3, Function&lt;Object[],V&gt; combinator) 
public static &lt;T1,T2,T3,T4,V&gt; Flux<V> combineLatest(Publisher&lt;? extends T1&gt; source1, Publisher&lt;? extends T2&gt; source2, Publisher&lt;? extends T3&gt; source3, Publisher&lt;? extends T4&gt; source4, Function&lt;Object[],V&gt; combinator)<br>…<br>public static &lt;T1,T2&gt; Flux&lt;Tuple2&lt;T1,T2&gt;&gt; zip(Publisher&lt;? extends T1&gt; source1, lisher&lt;? extends T2&gt; source2)<br>public static &lt;T1,T2,T3&gt; Flux&lt;Tuple3&lt;T1,T2,T3&gt;&gt; zip(Publisher&lt;? extends T1&gt; source1, lisher&lt;? extends T2&gt; source2, lisher&lt;? extends T3&gt; source3)<br>…<br>ヽ(o_ _)o摔倒，我也是服了project reactor 官方。</p>
<h3 id="常用的实例方法" class="article-heading"><a href="#常用的实例方法" class="headerlink" title="常用的实例方法"></a>常用的实例方法<a class="article-anchor" href="#常用的实例方法" aria-hidden="true"></a></h3><p>静态的方法介绍完了，但是实例方法比静态方法多太多，所以这里只举常用的几种介绍</p>
<h4 id="all-any-hasElement-hasElements" class="article-heading"><a href="#all-any-hasElement-hasElements" class="headerlink" title="all,any,hasElement,hasElements"></a>all,any,hasElement,hasElements<a class="article-anchor" href="#all-any-hasElement-hasElements" aria-hidden="true"></a></h4><p>这几个方法调用，均返回包涵一个Boolean信号的Mono。</p>
<ul>
<li>all(Predicate&lt;? super T&gt; predicate)表示所有值均满足条件</li>
<li>any(Predicate&lt;? super T&gt; predicate)表示存在一个值满足条件</li>
<li>hasElement(T t)表示是否存在该值</li>
<li>hasElements()表示是否拥有一个或多个元素</li>
</ul>
<h4 id="as-compose" class="article-heading"><a href="#as-compose" class="headerlink" title="as,compose"></a>as,compose<a class="article-anchor" href="#as-compose" aria-hidden="true"></a></h4><p>public final <P> P as(Function&lt;? super Flux<T>,P&gt; transformer)<br>转化flux为一个目标类型。<br>官方例子：flux.as(Mono::from).subscribe()<br>将flux通过Mono.from函数转化为mono<br>public final <V> Flux<V> compose(Function&lt;? super Flux<T>,? extends Publisher<V>&gt; transformer)<br>compose与as的区别是转化类型做了限制，必须继承Publisher，同时compose是惰性的。在很多时候，写法上没有差别如flux.compose(Mono::from).subscribe()   </p>
<h4 id="blockFirst-blockLast" class="article-heading"><a href="#blockFirst-blockLast" class="headerlink" title="blockFirst,blockLast"></a>blockFirst,blockLast<a class="article-anchor" href="#blockFirst-blockLast" aria-hidden="true"></a></h4><p>阻塞至第一个或者最后一个值处理完成</p>
<h4 id="butter系列" class="article-heading"><a href="#butter系列" class="headerlink" title="butter系列"></a>butter系列<a class="article-anchor" href="#butter系列" aria-hidden="true"></a></h4><p>该系列实例方法很多，作用是将一系列元素，分成一组或者多组，该方法可用在按组批量操作上，例如，以时间间隔分组，批量添加数据。</p>
<h4 id="cache" class="article-heading"><a href="#cache" class="headerlink" title="cache"></a>cache<a class="article-anchor" href="#cache" aria-hidden="true"></a></h4><p>如其名缓存，相当于复制一份用于接下来的操作，而当前的流将会被缓存起来，用于之后的操作。</p>
<h4 id="cancelOn" class="article-heading"><a href="#cancelOn" class="headerlink" title="cancelOn"></a>cancelOn<a class="article-anchor" href="#cancelOn" aria-hidden="true"></a></h4><p>public final Flux<T> cancelOn(Scheduler scheduler)<br>取消</p>
<h4 id="cast" class="article-heading"><a href="#cast" class="headerlink" title="cast"></a>cast<a class="article-anchor" href="#cast" aria-hidden="true"></a></h4><p>public final <E> Flux<E> cast(Class<E> clazz)
强转</p>
<h4 id="checkpoint" class="article-heading"><a href="#checkpoint" class="headerlink" title="checkpoint"></a>checkpoint<a class="article-anchor" href="#checkpoint" aria-hidden="true"></a></h4><p>用于检测当前节点，流中是否存在错误</p>
<h4 id="collect系列" class="article-heading"><a href="#collect系列" class="headerlink" title="collect系列"></a>collect系列<a class="article-anchor" href="#collect系列" aria-hidden="true"></a></h4><p>该系列实例方法，用于收集所有的元素到特定类型，如list、map等<br>处理完成时返回Mono</p>
<h4 id="concatMap系列-flatMap系列" class="article-heading"><a href="#concatMap系列-flatMap系列" class="headerlink" title="concatMap系列,flatMap系列"></a>concatMap系列,flatMap系列<a class="article-anchor" href="#concatMap系列-flatMap系列" aria-hidden="true"></a></h4><p>举例说明吧，[[1,2],[4,5],[6,7,8]] -&gt; [1,2,4,5,6,7,8]起这种转化作用<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/concatmap.png"><br>flatMap系列一样  </p>
<h4 id="concatWith" class="article-heading"><a href="#concatWith" class="headerlink" title="concatWith"></a>concatWith<a class="article-anchor" href="#concatWith" aria-hidden="true"></a></h4><p>与concatMap不同，这是相加<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/concat.png">  </p>
<h4 id="defaultIfEmpty" class="article-heading"><a href="#defaultIfEmpty" class="headerlink" title="defaultIfEmpty"></a>defaultIfEmpty<a class="article-anchor" href="#defaultIfEmpty" aria-hidden="true"></a></h4><p>public final Flux<T> defaultIfEmpty(T defaultV) 默认值  </p>
<h4 id="distinct" class="article-heading"><a href="#distinct" class="headerlink" title="distinct"></a>distinct<a class="article-anchor" href="#distinct" aria-hidden="true"></a></h4><p>public final Flux<T> distinct()<br>去重，相对与jdk8，多了下面两种方法<br>public final <V> Flux<T> distinct(Function&lt;? super T,? extends V&gt; keySelector)<br>public final &lt;V,C extends Collection&lt;? super V&gt;&gt; Flux<T> distinct(Function&lt;? super T,? extends V&gt; Supplier<C> distinctCollectionSupplier)
去除与V匹配的和第二个不怎么理解，，，这让我想到了filter  </p>
<h4 id="do系列" class="article-heading"><a href="#do系列" class="headerlink" title="do系列"></a>do系列<a class="article-anchor" href="#do系列" aria-hidden="true"></a></h4><p>还系列有doOnNext,doOnError,doOnCancel等等，均表示完成后触发</p>
<h4 id="elementAt" class="article-heading"><a href="#elementAt" class="headerlink" title="elementAt"></a>elementAt<a class="article-anchor" href="#elementAt" aria-hidden="true"></a></h4><p>返回某一位置的值，类型为Mono<T>，可以设置默认值</p>
<h4 id="filter" class="article-heading"><a href="#filter" class="headerlink" title="filter"></a>filter<a class="article-anchor" href="#filter" aria-hidden="true"></a></h4><p>public final Flux<T> filter(Predicate&lt;? super T&gt; p)<br>过滤出满足条件的  </p>
<h4 id="groupBy" class="article-heading"><a href="#groupBy" class="headerlink" title="groupBy"></a>groupBy<a class="article-anchor" href="#groupBy" aria-hidden="true"></a></h4><p>public final <K> Flux&lt;GroupedFlux&lt;K,T&gt;&gt; groupBy(Function&lt;? super T,? extends K&gt; keyMapper)<br><img data-src="https://raw.githubusercontent.com/reactor/reactor-core/v3.1.0.RC1/src/docs/marble/groupby.png"><br>分组，根据提供的keyMapper</p>
<h4 id="mark" class="article-heading"><a href="#mark" class="headerlink" title="mark"></a>mark<a class="article-anchor" href="#mark" aria-hidden="true"></a></h4><p>标记一下，写到h接下来还有一些要写，暂时不写了，太累。。。先写会实践（实践提前放在开头，入门）  </p>
<p><em>未完待续</em></p>
      
    </div>

    







<div>
  <ul class="post-copyright">
    <li class="post-copyright-author">
      <strong>本文作者： </strong>
      Mr.J
    </li>
    <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://jiangtj.com/articles/almond/Java%20ProjectReactor-Flux/">https://jiangtj.com/articles/almond/Java%20ProjectReactor-Flux/</a>
    <li class="post-copyright-license">
      <strong>版权声明： </strong>
      本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="creative-commons" class="svg-inline--fa fa-creative-commons icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512"><path fill="currentColor" d="M245.83 214.87l-33.22 17.28c-9.43-19.58-25.24-19.93-27.46-19.93-22.13 0-33.22 14.61-33.22 43.84 0 23.57 9.21 43.84 33.22 43.84 14.47 0 24.65-7.09 30.57-21.26l30.55 15.5c-6.17 11.51-25.69 38.98-65.1 38.98-22.6 0-73.96-10.32-73.96-77.05 0-58.69 43-77.06 72.63-77.06 30.72-.01 52.7 11.95 65.99 35.86zm143.05 0l-32.78 17.28c-9.5-19.77-25.72-19.93-27.9-19.93-22.14 0-33.22 14.61-33.22 43.84 0 23.55 9.23 43.84 33.22 43.84 14.45 0 24.65-7.09 30.54-21.26l31 15.5c-2.1 3.75-21.39 38.98-65.09 38.98-22.69 0-73.96-9.87-73.96-77.05 0-58.67 42.97-77.06 72.63-77.06 30.71-.01 52.58 11.95 65.56 35.86zM247.56 8.05C104.74 8.05 0 123.11 0 256.05c0 138.49 113.6 248 247.56 248 129.93 0 248.44-100.87 248.44-248 0-137.87-106.62-248-248.44-248zm.87 450.81c-112.54 0-203.7-93.04-203.7-202.81 0-105.42 85.43-203.27 203.72-203.27 112.53 0 202.82 89.46 202.82 203.26-.01 121.69-99.68 202.82-202.84 202.82z"></path></svg>BY-NC-SA</a> 许可协议。转载请注明出处！    </li>
  </ul>
</div>


    
<div class="post-tags">
  
  <a href="/tags/WebFlux/" rel="tag"># WebFlux</a>
  
  <a href="/tags/Reactor/" rel="tag"># Reactor</a>
  
  <a href="/tags/Reactive/" rel="tag"># Reactive</a>
  
</div>


    
    <div class="reward-container"><div>Buy me a cup of milkshake 🍨.</div><div class="reward-box"><div class="reward-box-card wechat">
  <img class="reward-image" src="/images/wechatpay.png" />
  
</div>
<div class="reward-box-card alipay">
  <img class="reward-image" src="/images/alipay.png" />
  
  <a class="reward-image-url" href="HTTPS://QR.ALIPAY.COM/FKX06416WJNHOWKMRQQFFE">点击跳转</a>
  
</div>
<div class="reward-box-card paypal">
  <img class="reward-image" src="/images/paypal.png" />
  
  <a class="reward-image-url" target="_blank" rel="noopener" href="https://www.paypal.me/jiangtj">https://www.paypal.me/jiangtj</a>
  
</div>
<div class="reward-box-card kofi">
  <img class="reward-image" src="/images/kofi.png" />
  
  <a class="reward-image-url" target="_blank" rel="noopener" href="https://ko-fi.com/jiangtj">https://ko-fi.com/jiangtj</a>
  
</div>
</div><div class="reward-group"><a class="reward-button wechat"><span><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="weixin" class="svg-inline--fa fa-weixin icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M385.2 167.6c6.4 0 12.6.3 18.8 1.1C387.4 90.3 303.3 32 207.7 32 100.5 32 13 104.8 13 197.4c0 53.4 29.3 97.5 77.9 131.6l-19.3 58.6 68-34.1c24.4 4.8 43.8 9.7 68.2 9.7 6.2 0 12.1-.3 18.3-.8-4-12.9-6.2-26.6-6.2-40.8-.1-84.9 72.9-154 165.3-154zm-104.5-52.9c14.5 0 24.2 9.7 24.2 24.4 0 14.5-9.7 24.2-24.2 24.2-14.8 0-29.3-9.7-29.3-24.2.1-14.7 14.6-24.4 29.3-24.4zm-136.4 48.6c-14.5 0-29.3-9.7-29.3-24.2 0-14.8 14.8-24.4 29.3-24.4 14.8 0 24.4 9.7 24.4 24.4 0 14.6-9.6 24.2-24.4 24.2zM563 319.4c0-77.9-77.9-141.3-165.4-141.3-92.7 0-165.4 63.4-165.4 141.3S305 460.7 397.6 460.7c19.3 0 38.9-5.1 58.6-9.9l53.4 29.3-14.8-48.6C534 402.1 563 363.2 563 319.4zm-219.1-24.5c-9.7 0-19.3-9.7-19.3-19.6 0-9.7 9.7-19.3 19.3-19.3 14.8 0 24.4 9.7 24.4 19.3 0 10-9.7 19.6-24.4 19.6zm107.1 0c-9.7 0-19.3-9.7-19.3-19.6 0-9.7 9.7-19.3 19.3-19.3 14.5 0 24.4 9.7 24.4 19.3.1 10-9.9 19.6-24.4 19.6z"></path></svg></span></a><a class="reward-button alipay"><span><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="alipay" class="svg-inline--fa fa-alipay icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M377.74 32H70.26C31.41 32 0 63.41 0 102.26v307.48C0 448.59 31.41 480 70.26 480h307.48c38.52 0 69.76-31.08 70.26-69.6-45.96-25.62-110.59-60.34-171.6-88.44-32.07 43.97-84.14 81-148.62 81-70.59 0-93.73-45.3-97.04-76.37-3.97-39.01 14.88-81.5 99.52-81.5 35.38 0 79.35 10.25 127.13 24.96 16.53-30.09 26.45-60.34 26.45-60.34h-178.2v-16.7h92.08v-31.24H88.28v-19.01h109.44V92.34h50.92v50.42h109.44v19.01H248.63v31.24h88.77s-15.21 46.62-38.35 90.92c48.93 16.7 100.01 36.04 148.62 52.74V102.26C447.83 63.57 416.43 32 377.74 32zM47.28 322.95c.99 20.17 10.25 53.73 69.93 53.73 52.07 0 92.58-39.68 117.87-72.9-44.63-18.68-84.48-31.41-109.44-31.41-67.45 0-79.35 33.06-78.36 50.58z"></path></svg></span></a><a class="reward-button paypal"><span><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="paypal" class="svg-inline--fa fa-paypal icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path fill="currentColor" d="M111.4 295.9c-3.5 19.2-17.4 108.7-21.5 134-.3 1.8-1 2.5-3 2.5H12.3c-7.6 0-13.1-6.6-12.1-13.9L58.8 46.6c1.5-9.6 10.1-16.9 20-16.9 152.3 0 165.1-3.7 204 11.4 60.1 23.3 65.6 79.5 44 140.3-21.5 62.6-72.5 89.5-140.1 90.3-43.4.7-69.5-7-75.3 24.2zM357.1 152c-1.8-1.3-2.5-1.8-3 1.3-2 11.4-5.1 22.5-8.8 33.6-39.9 113.8-150.5 103.9-204.5 103.9-6.1 0-10.1 3.3-10.9 9.4-22.6 140.4-27.1 169.7-27.1 169.7-1 7.1 3.5 12.9 10.6 12.9h63.5c8.6 0 15.7-6.3 17.4-14.9.7-5.4-1.1 6.1 14.4-91.3 4.6-22 14.3-19.7 29.3-19.7 71 0 126.4-28.8 142.9-112.3 6.5-34.8 4.6-71.4-23.8-92.6z"></path></svg></span></a><a class="reward-button kofi"><span><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="coffee" class="svg-inline--fa fa-coffee icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path fill="currentColor" d="M192 384h192c53 0 96-43 96-96h32c70.6 0 128-57.4 128-128S582.6 32 512 32H120c-13.3 0-24 10.7-24 24v232c0 53 43 96 96 96zM512 96c35.3 0 64 28.7 64 64s-28.7 64-64 64h-32V96h32zm47.7 384H48.3c-47.6 0-61-64-36-64h583.3c25 0 11.8 64-35.9 64z"></path></svg></span></a></div></div>    

    
    <footer class="post-footer">
      
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/articles/almond/Spring-data-jpa-and-Mybatis/" rel="prev" title="Spring Data Jpa与Mybatis的选择">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="chevron-left" class="svg-inline--fa fa-chevron-left icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path fill="currentColor" d="M34.52 239.03L228.87 44.69c9.37-9.37 24.57-9.37 33.94 0l22.67 22.67c9.36 9.36 9.37 24.52.04 33.9L131.49 256l154.02 154.75c9.34 9.38 9.32 24.54-.04 33.9l-22.67 22.67c-9.37 9.37-24.57 9.37-33.94 0L34.52 272.97c-9.37-9.37-9.37-24.57 0-33.94z"></path></svg>
      Spring Data Jpa与My...
    </a></div>
      <div class="post-nav-item">
    <a href="/articles/almond/dart-get-start/" rel="next" title="Dart之环境搭建">
      Dart之环境搭建
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="chevron-right" class="svg-inline--fa fa-chevron-right icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path fill="currentColor" d="M285.476 272.971L91.132 467.314c-9.373 9.373-24.569 9.373-33.941 0l-22.667-22.667c-9.357-9.357-9.375-24.522-.04-33.901L188.505 256 34.484 101.255c-9.335-9.379-9.317-24.544.04-33.901l22.667-22.667c9.373-9.373 24.569-9.373 33.941 0L285.475 239.03c9.373 9.372 9.373 24.568.001 33.941z"></path></svg>
    </a></div>
    </div>    </footer>
    
  </div>
</article>
</div>
        </div>
        




<div class="card comment-body disqus active">
<div id="disqus_thread"></div>
<script>
var disqus_config = function () {
this.page.url = 'https://jiangtj.com/articles/almond/Java%20ProjectReactor-Flux/';;  // Replace PAGE_URL with your page's canonical URL variable
this.page.identifier = 'articles/almond/Java ProjectReactor-Flux/'; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
};
(function() { // DON'T EDIT BELOW THIS LINE
var d = document, s = d.createElement('script');
s.src = 'https://jiangtj.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript>Please enable JavaScript to view the <a target="_blank" rel="noopener" href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    </div>



      </main>

      <footer class="footer">
        <div>
          <div class="copyright">
  
  &copy; 
  <span>2022</span>
  <span class="with-love">
    <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="heart" class="svg-inline--fa fa-heart icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M462.3 62.6C407.5 15.9 326 24.3 275.7 76.2L256 96.5l-19.7-20.3C186.1 24.3 104.5 15.9 49.7 62.6c-62.8 53.6-66.1 149.8-9.9 207.9l193.5 199.8c12.5 12.9 32.8 12.9 45.3 0l193.5-199.8c56.3-58.1 53-154.3-9.8-207.9z"></path></svg>
    <i class="[object Object]"></i>
  </span>
  <span class="author">Mr.J</span>
</div>

<div class="powered-by">
  由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> 强力驱动 v6.1.0
</div>

<span class="post-meta-divider">|</span>

<div class="theme-info">
  主题 – <a href="https://github.com/JiangTJ/hexo-theme-cake" class="theme-link" rel="noopener" target="_blank">Cake</a> v4.0.0
</div>

        </div>
      </footer>

    </div>

  </div>

  <div class="search-popup">
  <div class="search-header">
    <span class="search-icon"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="search" class="svg-inline--fa fa-search icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M505 442.7L405.3 343c-4.5-4.5-10.6-7-17-7H372c27.6-35.3 44-79.7 44-128C416 93.1 322.9 0 208 0S0 93.1 0 208s93.1 208 208 208c48.3 0 92.7-16.4 128-44v16.3c0 6.4 2.5 12.5 7 17l99.7 99.7c9.4 9.4 24.6 9.4 33.9 0l28.3-28.3c9.4-9.4 9.4-24.6.1-34zM208 336c-70.7 0-128-57.2-128-128 0-70.7 57.2-128 128-128 70.7 0 128 57.2 128 128 0 70.7-57.2 128-128 128z"></path></svg></span>
    <div class="search-input-container">
      <input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..."
        spellcheck="false" type="text" id="search-input">
    </div>
    <span class="popup-btn-close"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times-circle" class="svg-inline--fa fa-times-circle icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm121.6 313.1c4.7 4.7 4.7 12.3 0 17L338 377.6c-4.7 4.7-12.3 4.7-17 0L256 312l-65.1 65.6c-4.7 4.7-12.3 4.7-17 0L134.4 338c-4.7-4.7-4.7-12.3 0-17l65.6-65-65.6-65.1c-4.7-4.7-4.7-12.3 0-17l39.6-39.6c4.7-4.7 12.3-4.7 17 0l65 65.7 65.1-65.6c4.7-4.7 12.3-4.7 17 0l39.6 39.6c4.7 4.7 4.7 12.3 0 17L312 256l65.6 65.1z"></path></svg></span>
  </div>
  <div id="search-result"></div>
</div>
<div class="search-pop-overlay"></div>
<script id="ribbon" size="300" alpha="0.6" zIndex="-1" src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-ribbon@1/canvas-ribbon.js"></script><script>
((window.gitter = {}).chat = {}).options = {
  room: 'jiangtj/Lobby',
  activationElement: false
};
</script><script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script><script>
  (function () {
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
  })();
</script>
<div class="moon-menu">
  <div class="moon-menu-items">
    
    <div id="moon-menu-item-back2bottom" class="moon-menu-item">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="chevron-down" class="svg-inline--fa fa-chevron-down icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg>    </div>
    
    <div id="moon-menu-item-back2top" class="moon-menu-item">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="chevron-up" class="svg-inline--fa fa-chevron-up icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M240.971 130.524l194.343 194.343c9.373 9.373 9.373 24.569 0 33.941l-22.667 22.667c-9.357 9.357-24.522 9.375-33.901.04L224 227.495 69.255 381.516c-9.379 9.335-24.544 9.317-33.901-.04l-22.667-22.667c-9.373-9.373-9.373-24.569 0-33.941L207.03 130.525c9.372-9.373 24.568-9.373 33.941-.001z"></path></svg>    </div>
    
    <div id="moon-menu-item-chat" class="moon-menu-item">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="comments" class="svg-inline--fa fa-comments icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path fill="currentColor" d="M416 192c0-88.4-93.1-160-208-160S0 103.6 0 192c0 34.3 14.1 65.9 38 92-13.4 30.2-35.5 54.2-35.8 54.5-2.2 2.3-2.8 5.7-1.5 8.7S4.8 352 8 352c36.6 0 66.9-12.3 88.7-25 32.2 15.7 70.3 25 111.3 25 114.9 0 208-71.6 208-160zm122 220c23.9-26 38-57.7 38-92 0-66.9-53.5-124.2-129.3-148.1.9 6.6 1.3 13.3 1.3 20.1 0 105.9-107.7 192-240 192-10.8 0-21.3-.8-31.7-1.9C207.8 439.6 281.8 480 368 480c41 0 79.1-9.2 111.3-25 21.8 12.7 52.1 25 88.7 25 3.2 0 6.1-1.9 7.3-4.8 1.3-2.9.7-6.3-1.5-8.7-.3-.3-22.4-24.2-35.8-54.5z"></path></svg>    </div>
    
    <div id="moon-menu-item-switch_color" class="moon-menu-item">
      <svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="adjust" class="svg-inline--fa fa-adjust icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="currentColor" d="M8 256c0 136.966 111.033 248 248 248s248-111.034 248-248S392.966 8 256 8 8 119.033 8 256zm248 184V72c101.705 0 184 82.311 184 184 0 101.705-82.311 184-184 184z"></path></svg>    </div>
    
  </div>
  <div class="moon-menu-button">
    <svg class="moon-menu-bg">
      <circle class="moon-menu-cricle" cx="50%" cy="50%" r="44%"></circle>
      <circle class="moon-menu-border" cx="50%" cy="50%" r="48%"></circle>
    </svg>
    <div class="moon-menu-content">
      <div class="moon-menu-icon"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="ellipsis-v" class="svg-inline--fa fa-ellipsis-v icon" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 192 512"><path fill="currentColor" d="M96 184c39.8 0 72 32.2 72 72s-32.2 72-72 72-72-32.2-72-72 32.2-72 72-72zM24 80c0 39.8 32.2 72 72 72s72-32.2 72-72S135.8 8 96 8 24 40.2 24 80zm0 352c0 39.8 32.2 72 72 72s72-32.2 72-72-32.2-72-72-72-72 32.2-72 72z"></path></svg></div>
      <div class="moon-menu-text"></div>
    </div>
  </div>
</div><script src="/js/injector.js"></script>
<!-- hexo injector body_end start --><script>
// Check that service workers are supported
if ('serviceWorker' in navigator) {
  // Use the window load event to keep the page load performant
  window.addEventListener('load', () => {
    navigator.serviceWorker.register('/sw.js');
  });
}
</script>
<!-- hexo injector body_end end --></body>

</html>
